package com.jjwxc.jwjskandriod.activity;

import android.content.Intent;
import android.graphics.Paint;
import android.view.View;
import android.widget.TextView;

import com.jjwxc.jwjskandriod.R;
import com.jjwxc.jwjskandriod.config.BaseActivity;
import com.jjwxc.jwjskandriod.framework.utils.PreUtils;
import com.jjwxc.jwjskandriod.framework.utils.StUtils;
import com.jjwxc.jwjskandriod.readActivity.utils.UMConstant;
import com.jjwxc.jwjskandriod.widget.GjySerialnumberLayout;
import com.umeng.analytics.MobclickAgent;

public class AdolescentActivity extends BaseActivity {
    GjySerialnumberLayout gjyserial;
    TextView tv_appeal;
    TextView tv_queding;
    String mCode;

    @Override
    public int getContentViewId() {
        return R.layout.activity_adolescent;
    }

    @Override
    public void findView() {

        gjyserial = findViewById(R.id.gjyserial);
        tv_appeal = findViewById(R.id.tv_appeal);
        tv_queding = findViewById(R.id.tv_queding);
        tv_appeal.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        if (!PreUtils.getBoolean("QING_switch", false)) {
            setTitle("开启青少年模式");
            tv_queding.setText("开启青少年模式");
        } else {
            setTitle("关闭青少年模式");
            tv_queding.setText("关闭青少年模式");
        }
    }

    @Override
    public void setListener() {

        gjyserial.setOnInputListener(new GjySerialnumberLayout.OnInputListener() {
            @Override
            public void onSucess(String code) {
                mCode = code;
            }
        });
        tv_appeal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AdolescentActivity.this, AppealActivity.class);
                startActivity(intent);
            }
        });
        tv_queding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!StUtils.isEmpty(mCode)) {
                    if (PreUtils.getBoolean("QING_switch", false)) {
                        if (PreUtils.getString("QING_password", "").equals(mCode)) {
                            removeAllActivity();
                            PreUtils.setBoolean("QING_switch", false);
                            Intent intent = new Intent(AdolescentActivity.this, MainActivity.class);
                            startActivity(intent);
                            finish();

                        } else {
                            showToast("监护密码不正确");
                        }

                    } else {
                        PreUtils.setString("QING_password", mCode);
                        PreUtils.setBoolean("QING_switch", true);
                        removeAllActivity();
                        //跳转到青少年模式
                        Intent intent = new Intent(AdolescentActivity.this, AdolescentBookActivity.class);
                        startActivity(intent);
                        MobclickAgent.onEvent(AdolescentActivity.this, UMConstant.YOUNG_TYPE_ANDROID_CLICK);
                    }

                } else {
                    showToast("请输入监护密码");
                }
            }
        });
    }

    @Override
    public void afterCreate() {

    }
}
